 package com.xjtu.model;


import cn.hutool.core.date.DateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * 聊天记录
 * 设置文档所在集合
 */
//@Document("chat")
@Data
@NoArgsConstructor
public class Chat {

    @Id
    //文档的Id为ObjectId类型
    private String id;

    //发送方id
    private String from;

    //接收方id
    private String to;

    //聊天内容类型
    private ChatType type;

    //聊天内容
    private String content;

    //是否已读
    private boolean read;

    //发送时间
    private String time;

    public Chat(String from, String to, String content) {
        this(from, to, content, ChatType.TEXT);
    }

    public Chat(String from, String to, String content, ChatType chatType) {
        this.from = from;
        this.to = to;
        this.content = content;
        this.type = chatType;
        this.read = false;

        //默认使用当前时间
        this.time = DateTime.now().toString();
    }
}
